package com.marvels.approve.consum.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fintech.common.util.ApiResponse;
import com.marvels.approve.common.dto.JsonResult;
import com.marvels.approve.consum.ApproveConsumerExternalApi;
import com.marvels.approve.loan.dto.ApiResponseDTO;
import com.marvels.approve.loan.dto.KimGeResponseDTO;
import com.marvels.approve.loan.dto.KimGeXinQianInfoDTO;
import com.marvels.approve.loan.dto.PaymentResultDTO;
import com.marvels.approve.loan.dto.ZxDataReqDTO;
import com.marvels.approve.loan.dto.ZxDataRespDTO;
import com.marvels.approve.process.dto.IntBankCreditCard;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.externalservice.service.IntBankDataService;
import com.marvels.dubbo.externalservice.service.ProvidentFundService;
import com.marvels.dubbo.externalservice.service.PushFaceseSigService;

import cn.hutool.core.bean.BeanUtil;

@Component
public class ApproveConsumerExternalImpl implements ApproveConsumerExternalApi{

	@Autowired
	private IntBankDataService intBankDataService;
	
	@Autowired
	private PushFaceseSigService pushFaceSigService;
	
	@Autowired
	private  ProvidentFundService providentFundService;
	
	
	@Override
	public JsonResult<String> pushFacePush(Map<String, String> map) {
		try {
			String apiResult = pushFaceSigService.pushFacePush(map);
			JsonResult<String> result = (JsonResult<String>) 
					JSON.parseObject(JSONObject.toJSONString(apiResult), new TypeReference<JsonResult<String>>(){});
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.pushFacePush direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.pushFacePush error", e);
			return null;
		}
	}

	@Override
	public Map<String, Object> viewRiskInfoPositionData(Map<String, String> map) {
		try {
			Map<String, Object> result = intBankDataService.viewRiskInfoPositionData(map);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.viewRiskInfoPositionData direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.viewRiskInfoPositionData error", e);
			return null;
		}
	}

	@Override
	public List<IntBankCreditCard> intBankCreditCardLoanId(Map<String, String> map) {
		try {
			List<com.fintech.third.model.intbank.IntBankCreditCard> apiResult = intBankDataService.intBankCreditCardLoanId(map);
			List<IntBankCreditCard> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), IntBankCreditCard.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.intBankCreditCardLoanId direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.intBankCreditCardLoanId error", e);
			return null;
		}
	}

	@Override
	public List<Map<String, Object>> listgjj(Map<String, String> map) {
		try {
			List<Map<String, Object>> result = providentFundService.listgjj(map);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.listgjj direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.listgjj error", e);
			return null;
		}
	}

	@Override
	public ZxDataRespDTO getCreditData(ZxDataReqDTO reqDto, String dataProvider) {
		try {
			com.fintech.third.model.ZxDataReqDTO param = new com.fintech.third.model.ZxDataReqDTO();
			BeanUtil.copyProperties(reqDto, param);
			com.fintech.third.model.ZxDataRespDTO apiResult = intBankDataService.getCreditData(param,dataProvider);
			ZxDataRespDTO zxDataRespDTO = JSONObject.parseObject(JSONObject.toJSONString(apiResult), ZxDataRespDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.getCreditData direct call success!");
			return zxDataRespDTO;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.getCreditData error", e);
			return null;
		}
	}

	@Override
	public ZxDataRespDTO getDetailCreditData(ZxDataReqDTO reqDto, String dataProvider) {
		try {
			com.fintech.third.model.ZxDataReqDTO param = new com.fintech.third.model.ZxDataReqDTO();
			BeanUtil.copyProperties(reqDto, param);
			com.fintech.third.model.ZxDataRespDTO apiResult = intBankDataService.getDetailCreditData(param,dataProvider);
			ZxDataRespDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), ZxDataRespDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.getDetailCreditData direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.getDetailCreditData error", e);
			return null;
		}
	}


	@Override
	public KimGeResponseDTO getKimGeResponseDTO(Map map) {
		try {
			//com.fintech.third.model.kimge.KimGeResponse apiResult = intBankDataService.getKimGeResponseDTO(map);
			KimGeResponseDTO result = null;//JSONObject.parseObject(JSONObject.toJSONString(apiResult), KimGeResponseDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.getKimGeResponseDTO direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.getKimGeResponseDTO error", e);
			return null;
		}
	}

	@Override
	public KimGeResponseDTO downloadDocuments(Map map) {
		try {
			//com.fintech.third.model.kimge.KimGeResponse apiResult = intBankDataService.downloadDocuments(map);
			KimGeResponseDTO result = null;//JSONObject.parseObject(JSONObject.toJSONString(apiResult), KimGeResponseDTO.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.downloadDocuments direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.downloadDocuments error", e);
			return null;
		}
	}

	


	@Override
	public ApiResponseDTO<KimGeXinQianInfoDTO> contractInitiation(Map map) {
		try {
			//ApiResponse<com.fintech.third.model.kimge.KimGeXinQianInfo> apiResult = intBankDataService.contractInitiation(map);
			ApiResponseDTO<KimGeXinQianInfoDTO> result = null;//(ApiResponseDTO<KimGeXinQianInfoDTO>) 
					//JSON.parseObject(JSONObject.toJSONString(apiResult), new TypeReference<ApiResponseDTO<KimGeXinQianInfoDTO>>(){});
			MarvelsLogUtil.getInstance().info("ApproveConsumerExternalApi.contractInitiation direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerExternalApi.contractInitiation error", e);
			return null;
		}
	}



}
